package com.longrise.android.byjk.plugins.aboutme;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.common.base.BaseActivity;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.PersonalInfoActivity;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.PersonalInfoContract;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.SettingPresenter;
import com.longrise.common.utils.ActivityUtil;
import com.longrise.android.byjk.utils.Tracker_Google;


/**
 * Created by godliness on 2017/3/7.
 * bb 设置
 */

public class SettingActivity extends BaseActivity implements PersonalInfoContract.SettingView, View.OnClickListener {

    private static final String TAG = "SettingActivity";

    private RelativeLayout mPerson;
    private RelativeLayout mZHAQ;
    private RelativeLayout mCache;
    private RelativeLayout mShare;
    private RelativeLayout mCheck;
    private TextView mVersionCode;
    private RelativeLayout mSuggest;
    private RelativeLayout mAbout;
    private RelativeLayout mExit;

    private PersonalInfoContract.SettingPresenters mSetPresenter;
    private Toolbar mToolbar;

    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_setting;
    }

    public void initPresenter() {
        mSetPresenter = new SettingPresenter(this, this);
        mSetPresenter.init();
    }

    @Override
    public void initView() {
        mToolbar = (Toolbar) findViewById(R.id.byjk_toolbar);
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);

        mPerson = (RelativeLayout) findViewById(R.id.grzl_settingact);
        mZHAQ = (RelativeLayout) findViewById(R.id.zhaq_settingact);
//        mCache = (RelativeLayout) findViewById(R.id.cache_settingact);
//        mShare = (RelativeLayout) findViewById(R.id.sharebb_settingact);
        mCheck = (RelativeLayout) findViewById(R.id.checkupdate_settingact);
        mVersionCode = (TextView) findViewById(R.id.tv_version);
        mSuggest = (RelativeLayout) findViewById(R.id.suggest_settingact);
//        mAbout = (RelativeLayout) findViewById(R.id.aboutbb_settingact);
        mExit = (RelativeLayout) findViewById(R.id.exitbb_settingact);

        onEvent();

        Tracker_Google.getInstance().addGoogleScreenName("系统设置");
        initPresenter();
    }

    private void onEvent() {
        if (mPerson != null) {
            mPerson.setOnClickListener(this);
        }
        if (mZHAQ != null) {
            mZHAQ.setOnClickListener(this);
        }
//        if (mCache != null) {
//            mCache.setOnClickListener(this);
//        }
//        if (mShare != null) {
//            mShare.setOnClickListener(this);
//        }
        if (mCheck != null) {
            mCheck.setOnClickListener(this);
        }
        if (mSuggest != null) {
            mSuggest.setOnClickListener(this);
        }
//        if (mAbout != null) {
//            mAbout.setOnClickListener(this);
//        }
        if (mExit != null) {
            mExit.setOnClickListener(this);
        }
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSetPresenter.colse();
            }
        });
    }

    @Override
    public void setVersionCode(String code) {
        mVersionCode.setText(code);
    }

    @Override
    public void setTitle(String title) {
        mToolbar.setTitle(title);
    }

    @Override
    public void close() {
        finish();
    }

    @Override
    public void removeFromActivityUtils() {
        ActivityUtil.removeActivity(this);
    }

    @Override
    public void startActivityForR(Intent intent, int requestCode) {
        this.startActivityForResult(intent, requestCode);
    }

    @Override
    public void startActivityForR(int requestCode, Class<?> cls) {
        Intent resultIntent = new Intent(this, cls);
        this.startActivityForResult(resultIntent, requestCode);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mSetPresenter.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.grzl_settingact:
                startActivity(PersonalInfoActivity.class);
                break;

            case R.id.zhaq_settingact:
                startActivity(SecurityActivity.class);
                break;

//            case R.id.cache_settingact:
//                startActivity(CacheSettingLFView.class);
//                break;

//            case R.id.sharebb_settingact:
//                startActivity(ShareAPPLFView.class);
//                break;

            case R.id.checkupdate_settingact:
                mSetPresenter.jumpCheckUpdate();
                break;

            case R.id.suggest_settingact:
                startActivity(SuggestionLFView.class);
                break;

//            case R.id.aboutbb_settingact:
//                startActivity(AboutBBTLFView.class);
//                break;

            case R.id.exitbb_settingact:
                mSetPresenter.exit();
                break;

            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
